/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package javaapplication3;

import java.awt.Point;
import java.util.Timer;

/**
 *
 * @author DeLac
 */
public class Nemico extends Player {
    protected Timer timer_azione_IA;


    public  Nemico(String nome){
        super(nome);
        timer_azione_IA = new Timer();
        final Player this_instance = this;
        addMouseListener(new java.awt.event.MouseAdapter() {
          public void mousePressed(java.awt.event.MouseEvent evt)
          {
            System.out.println("richiesta attacco");
            MainForm.getInstance().getMainPlayer().attacca(this_instance);
          }
        });
    }

    @Override
    public void run(){
        vagabonda();
        super.run();

    }

    private void vagabonda(){
       Nemico_task vagabonda = new Nemico_task(-1,null);
       timer_azione_IA.schedule(vagabonda, 0);
        
    }

    

    public void cammina(Point p, int distanza){
        super.cammina(p, distanza);
    }



      private class Nemico_task extends Player_task {

         int azione;
         java.util.ArrayList<String> path;

      public Nemico_task (int azione, java.util.ArrayList<String> path){
          super(azione, path);
          this.azione = azione;
          this.path = path;
      }


      public void run(){
            if (azione==-1) {perform_vagabonda();}
            else super.run();
                       }

      public void perform_vagabonda(){

        double segnox =  Math.random();
        double segnoy =  Math.random();
        int x =  (int)(Math.random() * 50) ;
        int y =  (int)(Math.random() * 50) ;
        if (segnox > 0.5) {x=-x;}
        if (segnoy > 0.5) {y=-y;}
        x = x + getLocation().x;
        y = y + getLocation().y;
        System.out.println(getLocation());
        System.out.println(x+" "+y);
        cammina(new Point (x,y), 0);
        try{while (stato!=STAND) {thread.sleep(2000);}}catch(Exception ex){};
        try{thread.sleep(2000);}catch(Exception ex){};
        perform_vagabonda();
      }




     }

}
